<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h2>电影列表</h2>
        <input type="text" v-model="newMovies" autofocus />
        <button @click="handleClick">添加</button>
        <ul>
            <li v-for="(item,index) in movies" :key="item">{{index+1}}.{{item}}</li>
        </ul>
        <button @click="insertMovies">插入电影</button>
        <h2>遍历对象</h2>
        <ol>
            <li v-for="(value,key,index) in info">{{value}}--{{key}}--{{index}}</li>
        </ol>
        <h2>遍历数字</h2>
        <ul>
            <li v-for="(num,index) in 10">{{num}}---{{index}}</li>
        </ul>
    </div>
    <script src="../../js/vue.js"></script>
    <script>
        const dcl = {
            data() {
                return {
                    newMovies: '',
                    movies: ['大话西游', '阿甘正传', '教父', '肖申克的救赎'],
                    info: {
                        name: 'Steve Jobs',
                        age: 18,
                        gender: 'male'
                    },
                }
            },
            methods: {
                handleClick() {
                    if (this.newMovies) {
                        this.movies.push(this.newMovies)
                    }
                    this.newMovies = ''
                },
                insertMovies() {
                    // 从索引2的位置删除0个 增加功夫
                    this.movies.splice(2, 1, '功夫')
                }
            }
        }
        Vue.createApp(dcl).mount('#app');
    </script>
</body>

</html>